<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class News extends CI_Controller {
	public function __construct()
	{
		parent::__construct();
		$this->load->model('news_model');
		$this->load->library('form_validation');
		$this->load->helper(array('form','url')); 
	}

	public function index()
	{
		$data['news'] = $this->news_model->get_news();

		$this->load->view('news/list',$data);
	}

	public function addpage()
	{
		$this->load->view('news/addpage');
	}

	public function addaction()
	{ 
  		$this->form_validation->set_rules('title','标题', 'trim|required|min_length[5]');

  		$bool = $this->form_validation->run();

  		if(!$bool){
  			$this->load->view('news/addpage');
  		}else{
  			$this->news_model->additem();
  			$this->load->view('news/success');
  		}
	}
}